package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ProductController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/6 13:45
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product/product")
public class ProductController {
    @Resource
    private ProductService productService;



    /**
     * 商品的上下架状态修改
     * @return
     */
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status){
        productService.updateStatus(id,status);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 跟新审核状态
     * @param id
     * @param auditStatus
     * @return
     */
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable Long id,
                                    @PathVariable Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        productService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id修改
     * @param product
     * @return
     */
    @PutMapping("updateById")
    public Result updateById(@RequestBody Product product){
        productService.updateById(product);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable Long id){
        Product product = productService.getById(id);
        return Result.build(product,ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存商品信息
     * @param product
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody Product product){
        productService.save(product);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 分页带条件查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize,
                             ProductDto productDto){
        PageInfo<Product> page = productService.findByPage(pageNum,pageSize,productDto);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }
}
